﻿#!/usr/bin/perl
use strict;
use Storable;

my %to_code = %{retrieve "D:/toCode.txt"};
open my $output, ">", "map.html";

print $output "<html><head><body>\n<table border=1 height=\"100%\" width=\"100%\">";
my $data =  "Scotland,North Sea,North Sea,Norway,Sweden,Baltic Sea,Baltic Sea,Estonia,Russia|".
			"United Kingdom,North Sea,North Sea,Denmark,Sweden,Baltic Sea(Gotland?),Baltic Sea,Latvia,Russia|".
			"United Kingdom,North Sea,North Sea,Denmark,Baltic Sea,Baltic Sea,Baltic Sea,Lithuania,Belarus|".
			"United Kingdom,North Sea,The Netherlands,Germany,Germany,Poland,Poland,Belarus,Belarus|".
			"English Channel,English Channel,Belgium,Germany,Germany,Poland,Poland,Ukraine,Ukraine|".
			"France,France,France,Germany,Bavaria,Czech Republic,Slovenia,Romania,Ukraine|".
			"France,France,France,Switzerland,Austria,Austria,Hungary,Romania,Black Sea|".
			"France,France,France,Italy,Italy,Balkan,Balkan,Bulgaria,Black Sea|".
			"Spain,Spain,Mediterranean Sea,Mediterranean Sea,Italy,Mediterranean Sea,Greece,Greece,Turkey";
my @lines = split /\|/, $data;
my $rows = scalar(@lines);
foreach my $line (@lines)
{
	print $output "<tr>\n";
	my @cells = split /,/, $line;
	my $cols = scalar(@cells);
	foreach my $country (@cells)
	{
		print $output "<td width=\"".(100/$cols)."%\" height=\"".(100/$rows)."%\" align=\"center\" ";
		my $code = $to_code{$country};
		if ( $code )
		{
			my $let = substr $code, 0, 1;
			my $add = "http://www.crwflags.com/fotw/images/$let/$code.gif\n";
			print $output "><img src = \"$add\" height=\"100\" width=\"150\">";
		}
		else
		{
			if ( $country =~ m/Sea/ or $country =~ m/Channel/ )
			{
				print $output "bgcolor=\"blue\"";
			}
			print $output ">".$country;
		}
		print $output "</td>\n";
	}
	print $output "</tr>\n";
}
print $output "</table>\n</body></head></html>";